package first.niuke.midding;

import java.util.ArrayList;

/**
 * @ClassName NC161
 * @description:
 * @author: 荣燊
 * @create: 2021-06-23 14:16
 **/
public class NC161 {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
    }

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    ArrayList<Integer> list = new ArrayList<>();
    // 二叉树的中序遍历
    public int[] inorderTraversal (TreeNode root) {
        // write code here
        dfs(root);
        int[] ints = new int[list.size()];
        for (int i=0; i<list.size(); i++) {
            ints[i] = list.get(i);
        }
        return ints;
    }

    void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(root.left);
        list.add(root.val);
        dfs(root.right);
    }

}


